Std_ObtainItem::
	checkitemtype VAR_0x8000
	compare VAR_RESULT, POCKET_KEY_ITEMS
	call_if_eq EventScript_FixRandItemBug
	compare VAR_RESULT, POCKET_TM_HM
	call_if_eq EventScript_FixRandItemBug
	additem VAR_0x8000, VAR_0x8001
	setvar VAR_UNUSED_0x8014, 0
	copyvar VAR_0x8006, VAR_0x8000
	copyvar VAR_0x8007, VAR_RESULT
	call EventScript_ObtainItemMessage
	return

EventScript_FixRandItemBug::
	setvar VAR_UNUSED_0x8014, 2
	return

EventScript_ObtainItemMessage::
	bufferitemnameplural 1, VAR_0x8000, VAR_0x8001
	checkitemtype VAR_0x8000
	call EventScript_BufferPocketNameAndTryFanfare
	compare VAR_0x8007, 1
	call_if_eq EventScript_ObtainedItem
	compare VAR_0x8007, 0
	call_if_eq EventScript_NoRoomForItem
	return

EventScript_BufferPocketNameAndTryFanfare::
	switch VAR_RESULT
	case POCKET_ITEMS, EventScript_BufferItemsPocket
	case POCKET_KEY_ITEMS, EventScript_BufferKeyItemsPocket
	case POCKET_POKE_BALLS, EventScript_BufferPokeballsPocket
	case POCKET_TM_HM, EventScript_BufferTMHMsPocket
	case POCKET_BERRIES, EventScript_BufferBerriesPocket
	end

EventScript_BufferItemsPocket::
	bufferstdstring 2, STDSTRING_ITEMS
	compare VAR_0x8007, 1
	call_if_eq EventScript_PlayFanfareObtainedItem
	return

EventScript_BufferKeyItemsPocket::
	bufferstdstring 2, STDSTRING_KEYITEMS
	compare VAR_0x8007, 1
	call_if_eq EventScript_PlayFanfareObtainedItem
	return

EventScript_BufferPokeballsPocket::
	bufferstdstring 2, STDSTRING_POKEBALLS
	compare VAR_0x8007, 1
	call_if_eq EventScript_PlayFanfareObtainedItem
	return

EventScript_BufferTMHMsPocket::
	bufferstdstring 2, STDSTRING_TMHMS
	compare VAR_0x8007, 1
	call_if_eq EventScript_PlayFanfareObtainedTMHM
	return

EventScript_BufferBerriesPocket::
	bufferstdstring 2, STDSTRING_BERRIES
	compare VAR_0x8007, 1
	call_if_eq EventScript_PlayFanfareObtainedItem
	return

EventScript_ObtainedItem::
	message gText_ObtainedTheItem
	delay 10
	showitemdesc
	waitfanfare
	msgbox gText_PutItemInPocket, MSGBOX_DEFAULT
	hideitemdesc
	setvar VAR_RESULT, 1
	return

EventScript_NoRoomForItem::
	setvar VAR_RESULT, 0
	return

EventScript_PlayFanfareObtainedItem::
	playfanfare MUS_OBTAIN_ITEM
	return

EventScript_PlayFanfareObtainedTMHM::
	playfanfare MUS_OBTAIN_TMHM
	return

Std_ObtainDecoration::
	adddecoration VAR_0x8000
	copyvar VAR_0x8007, VAR_RESULT
	call EventScript_ObtainDecorationMessage
	return

EventScript_ObtainDecorationMessage::
	bufferdecorationname 1, VAR_0x8000
	compare VAR_0x8007, 1
	call_if_eq EventScript_ObtainedDecor
	compare VAR_0x8007, 0
	call_if_eq EventScript_NoRoomForDecor
	return

EventScript_ObtainedDecor::
	playfanfare MUS_OBTAIN_ITEM
	message gText_ObtainedTheDecor
	waitfanfare
	msgbox gText_TheDecorWasTransferredToThePC, MSGBOX_DEFAULT
	setvar VAR_RESULT, 1
	return

EventScript_NoRoomForDecor::
	setvar VAR_RESULT, 0
	return

Std_FindItem::
	lock
	faceplayer
	waitse
	checkitemtype VAR_0x8000
	compare VAR_RESULT, POCKET_KEY_ITEMS
	goto_if_eq Std_FindItemKeep
	compare VAR_RESULT, POCKET_TM_HM
	goto_if_eq Std_FindItemKeep
	setvar VAR_UNUSED_0x8014, 1
	additem VAR_0x8000, VAR_0x8001
Std_FindItemKeep::
	copyvar VAR_0x8004, VAR_0x8000
	copyvar VAR_0x8006, VAR_0x8000
	copyvar VAR_0x8005, VAR_0x8001
	checkitemspace VAR_0x8000, VAR_0x8001
	copyvar VAR_0x8007, VAR_RESULT
	bufferitemnameplural 1, VAR_0x8000, VAR_0x8001
	checkitemtype VAR_0x8000
	call EventScript_BufferPocketNameAndTryFanfare
	compare VAR_0x8007, 1
	call_if_eq EventScript_PickUpItem
	compare VAR_0x8007, 0
	call_if_eq EventScript_NoRoomToPickUpItem
	release
	return

EventScript_PickUpItem::
	removeobject VAR_LAST_TALKED
	setvar VAR_UNUSED_0x8014, 2
	additem VAR_0x8004, VAR_0x8005
	setvar VAR_UNUSED_0x8014, 0
	copyvar VAR_0x8006 VAR_0x8004
	specialvar VAR_RESULT, BufferTMHMMoveName
	copyvar VAR_0x8008, VAR_RESULT
	compare VAR_0x8008, 1
	call_if_eq EventScript_FoundTMHM
	compare VAR_0x8008, 0
	call_if_eq EventScript_FoundItem
	delay 10
	showitemdesc
	waitfanfare
	waitmessage
	bufferitemnameplural 1, VAR_0x8004, VAR_0x8005
	pyramid_inchallenge
	compare VAR_RESULT, 1
	goto_if_eq EventScript_PutBattlePyramidItemInBag
	msgbox gText_PutItemInPocket, MSGBOX_DEFAULT
	hideitemdesc
	return

EventScript_PutBattlePyramidItemInBag::
	msgbox gText_PlayerPutItemInBag, MSGBOX_DEFAULT
	hideitemdesc
	return

EventScript_FoundTMHM::
	bufferitemnameplural 0, VAR_0x8004, VAR_0x8005
	message gText_PlayerFoundOneTMHM
	return

EventScript_FoundItem::
	message gText_PlayerFoundOneItem
	return

EventScript_NoRoomToPickUpItem::
	msgbox gText_ObtainedTheItem, MSGBOX_DEFAULT
	msgbox gText_TooBadBagIsFull, MSGBOX_DEFAULT
	setvar VAR_RESULT, 0
	setvar VAR_UNUSED_0x8014, 0
	return

EventScript_HiddenItemScript::
	lockall
	waitse
	checkitemtype VAR_0x8005
	compare VAR_RESULT, POCKET_KEY_ITEMS
	call_if_eq EventScript_FixRandItemBug
	compare VAR_RESULT, POCKET_TM_HM
	call_if_eq EventScript_FixRandItemBug
	additem VAR_0x8005
	setvar VAR_UNUSED_0x8014, 0
	copyvar VAR_0x8005, VAR_0x8000
	copyvar VAR_0x8006, VAR_0x8005
	copyvar VAR_0x8007, VAR_RESULT
	bufferitemnameplural 1, VAR_0x8005, 1
	checkitemtype VAR_0x8005
	call EventScript_BufferPocketNameAndTryFanfare
	compare VAR_0x8007, 1
	goto_if_eq EventScript_PickUpHiddenItem
	compare VAR_0x8007, 0
	goto_if_eq EventScript_NoRoomForHiddenItem
	end

EventScript_PickUpHiddenItem::
	copyvar VAR_0x8008, VAR_0x8004
	copyvar VAR_0x8004, VAR_0x8005
	specialvar VAR_RESULT, BufferTMHMMoveName
	compare VAR_RESULT, 1
	goto_if_eq EventScript_FoundHiddenTMHM
	compare VAR_RESULT, 0
	goto_if_eq EventScript_FoundHiddenItem
	end

EventScript_FoundHiddenTMHM::
	bufferitemnameplural 0, VAR_0x8004, 1
	message gText_PlayerFoundOneTMHM
	goto EventScript_PutHiddenItemInPocket
	end

EventScript_FoundHiddenItem::
	message gText_PlayerFoundOneItem
	goto EventScript_PutHiddenItemInPocket
	end

EventScript_PutHiddenItemInPocket::
	delay 10
	showitemdesc
	waitmessage
	waitfanfare
	bufferitemnameplural 1, VAR_0x8004, 1
	copyvar VAR_0x8004, VAR_0x8008
	msgbox gText_PutItemInPocket, MSGBOX_DEFAULT
	hideitemdesc
	special TryPutTreasureInvestigatorsOnAir
	special SetHiddenItemFlag
	releaseall
	end

EventScript_NoRoomForHiddenItem::
	msgbox gText_PlayerFoundOneItem, MSGBOX_DEFAULT
	msgbox gText_TooBadBagIsFull, MSGBOX_DEFAULT
	setvar VAR_RESULT, 0
	releaseall
	end
